import type { ConsultIllness, PartialConsult } from './../../types/consult.d'
import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { ConsultType } from '@/enums'
export const useConsultStore = defineStore(
  'consult',
  () => {
    // 问诊记录状态
    const consult = ref<PartialConsult>({})
    /** 修改问诊类型 */
    const setType = (val: ConsultType) => (consult.value.type = val)
    // 修改极速问诊类型
    const setIllnessType = (val: 0 | 1) => (consult.value.illnessType = val)
    // 修改科室
    const setDepId = (val: string) => (consult.value.depId = val)

    // 修改病情描述相关信息
    const setIllness = (val: ConsultIllness) => {
      consult.value.illnessDesc = val.illnessDesc
      consult.value.illnessTime = val.illnessTime
      consult.value.consultFlag = val.consultFlag
      consult.value.pictures = val.pictures
    }
    // 修改患者
    const setPatientId = (val: string) => (consult.value.patientId = val)
    const setCouponId = (val: string) => (consult.value.couponId = val)
    // 清空记录
    const clear = () => {
      consult.value = {}
    }
    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllness,
      setPatientId,
      setCouponId,
      clear
    }
  },
  {
    persist: true
  }
)
